class EventEmitter{
    constructor(){
        this.eventlist = {}
    }
    on(eventname,cb){
        if(this.eventlist[eventname]){
            this.eventlist[eventname].push(cb)
        }else{
            this.eventlist[eventname] = [cb]
        }
    }
    off(eventname,cb){
        if(this.eventlist[eventname]){
            this.eventlist[eventname] = this.eventlist[eventname].filter(item=>item!=cb)
        }
    }
    emit(eventname){
        if(this.eventlist[eventname]){
            this.eventlist[eventname].forEach(cb=>{
                cb()
            })
        }
    }
    once(eventname,cb){
        const wrapper = ()=>{
            cb()
            this.off(eventname,wrapper)
        }
        this.on(eventname,wrapper)
    //    this.off(eventname,cb)
    }
}
let _event = new EventEmitter()
function kang(){
    console.log('康总买房')
}
function ji(){
    console.log('ji总买房')
}
function cheng(){
    console.log('cheng总买房')
}
_event.on('hashouse',kang)
_event.once('hashouse',ji)
_event.on('hascar',cheng)
_event.emit('hashouse')
_event.emit('hascar')
